<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->

    </BasicTable>

    <!-- 表单区域 -->
    <ModelInfoModal @register="registerModal" @success="handleSuccess"></ModelInfoModal>
  </div>
</template>

<script lang="ts" name="device-modelInfo" setup>
  import { ref, computed, unref, watch } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import ModelInfoModal from './modules/ModelInfoModal.vue'
  import { columns, searchFormSchema } from './ModelstateInfo.data';
  import { list } from './ModelstateInfo.api';

  const checkedKeys = ref<Array<string | number>>([]);
  const props = defineProps({
    deviceId: { type: Number }
  });
  //注册model
  const [registerModal, { openModal }] = useModal();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '最新数据',
      api: list,
      columns,
      canResize: false,
      formConfig: {
        labelWidth: 120, // 设置所有的label宽
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
      },
      showActionColumn: false,
      beforeFetch: (params) => {
        return Object.assign(params, { deviceId: props.deviceId });
      },
      actionColumn: {
        width: 120,
      },
    },
  })

  const [registerTable, { reload }, { selectedRowKeys }] = tableContext


  watch(
    () => props.deviceId,
    (val : number, prevVal : number) => {
      if (prevVal != undefined)
        reload();
    },
    {
      immediate: true,
    }
  );
  /**
   * 成功回调
   */
  function handleSuccess({ isUpdate, values }) {
    reload();
  }
</script>
<style scoped>

</style>
